function ngdomSpriteItem__Door(x, y, open, key) {
	ngdomSpriteItem__Door.prototype.base.constructor.call(this, x, y);
	if (!this.engine) return;
	
	this.speed = 0;
	this.animateHover = false;
	this.type = 'door';
	this.canTake = false;
	this.collidesWithWalls = false;
	this.open = !!open;
	this.locked = !!key;
	this.key = key;
	this.autoOpen = true;
	this.autoUnlock = true;
	this.arriveEarlyStayLate = true;
	this.direction = 3;
	this.size = { width: 64, height: 32 };
	this.cssClass = 'door';
	
	if (typeof(x) == 'object') $.extend(true, this, x);
}
ngdomSpriteItem__Door.inherits(ngdomSpriteItem);
ngdomSpriteItem__Door.prototype.enterScene = function () {
	ngdomSpriteItem__Door.prototype.base.enterScene.call(this);
	this.updateDoor();
};
ngdomSpriteItem__Door.prototype.updateDoor = function () {
	if (this.locked && this.autoUnlock) {
		var haskey = true;
		if ($.isArray(this.key))
			$.each(this.key, function (index, key) {
				haskey = haskey && ngdom.Engine.player.inventory.has(key);
			});
		else
			haskey = ngdom.Engine.player.inventory.has(this.key);
			
		this.locked = !haskey;
	}
	
	if (!this.open && this.autoOpen && !this.locked)
		this.open = true;
	
	var start = { 
		x: Math.floor((this.position.x - this.size.width / 2) / ngdom.Engine.wallGridScale), 
		y: Math.floor((this.position.y - this.size.height / 2) / ngdom.Engine.wallGridScale) 
	};
	var end = { 
		x: start.x + Math.floor(this.size.width / ngdom.Engine.wallGridScale), 
		y: start.y + Math.floor(this.size.height / ngdom.Engine.wallGridScale) 
	};
	for (var x = start.x; x <= end.x; x++) {
		for (var y = start.y; y <= end.y; y++) {
			if (this.open
				&& this.engine.map.grid[this.engine.map.position.x][this.engine.map.position.y]
				.walls[x + (y * ngdom.Engine.wallGridSize.width)] >= 100
				)
				this.engine.map.grid[this.engine.map.position.x][this.engine.map.position.y]
					.walls[x + (y * ngdom.Engine.wallGridSize.width)] -= 100;
			else
			if (!this.open
				&& this.engine.map.grid[this.engine.map.position.x][this.engine.map.position.y]
				.walls[x + (y * ngdom.Engine.wallGridSize.width)] < 100
				)
				this.engine.map.grid[this.engine.map.position.x][this.engine.map.position.y]
					.walls[x + (y * ngdom.Engine.wallGridSize.width)] += 100;
		}
	}
};
ngdomSpriteItem__Door.prototype.setSprite = function () {

	if (!this.open)
		ngdomSpriteItem__Door.prototype.base.setSprite.call(this);
	else {
		var sprite, vertical;
		
		if (this.sprites.open) { sprite = this.sprites.open; vertical = false; }
		else if (this.direction == 1) { sprite = this.sprites.open_u; vertical = true; }
		else if (this.direction == 2) { sprite = this.sprites.open_r; vertical = false; }
		else if (this.direction == 3) { sprite = this.sprites.open_d; vertical = true; }
		else if (this.direction == 4) { sprite = this.sprites.open_l; vertical = false; }
		
		if (!sprite) this.el.hide();
		else this.activateSprite(sprite, vertical);
	}
};
ngdomSpriteItem__Door.prototype.save = function () {
	return { open: this.open, locked: this.locked };
};
ngdomSpriteItem__Door.prototype.load = function (data) {
	this.open = data.open;
	this.locked = data.locked;
};
ngdomSpriteItem__Door.prototype.collideWithPlayer = function () { 
	//TODO
};